package com.xiaoyuanxing.demo.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xiaoyuanxing.demo.entity.Talk;
import com.xiaoyuanxing.demo.entity.TalkComment;
import com.xiaoyuanxing.demo.mapper.TalkCommentMapper;
import com.xiaoyuanxing.demo.mapper.TalkMapper;
import com.xiaoyuanxing.demo.service.TalkService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/*
 **@author LuoShengYing
 **@date 2021/5/28
 */
@Service("talkService")
public class TalkServiceImpl implements TalkService {

    @Resource
    private TalkMapper talkMapper;

    @Resource
    private TalkCommentMapper talkCommentMapper;

    @Override
    public Page<Talk> getAllTalks(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return talkMapper.selectAllTalks();
    }

    @Override
    public boolean createNewTalk(Talk talk) {
        return talkMapper.insertTalk(talk);
    }

    @Override
    public boolean deleteTalk(int talkID) {
        return talkMapper.deleteTalk(talkID);
    }

    @Override
    public int getCommentCount(int talkID) {
        return talkCommentMapper.selectTalkCommentCount(talkID);
    }

    @Override
    public Page<TalkComment> getComments(int talkID, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return talkCommentMapper.selectTalkComments(talkID);
    }

    @Override
    public boolean createdNewComment(TalkComment talkComment) {
        return talkCommentMapper.insertTalkComment(talkComment);
    }

    @Override
    public boolean deleteTalkComments(int talkID) {
        return talkCommentMapper.deleteTalkComments(talkID);
    }
}
